import Vue from "vue"
import VueRouter from "vue-router"
import Login from "@/views/Login.vue"
import Main from "@/views/Main.vue"
import gzhRouter from "@/router/gzh-router"
import rout from "@/router/qkprouter"
import lmh from "@/router/lmh-router"
import slf from "@/router/slf_router"
import lbrouter from "@/router/lbrouter"
import { Message } from "element-ui"
Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    redirect: "/login",
  },
  {
    path: "/login",
    name: "login",
    component: Login,
  },
  {
    path: "/main",
    name: "main",
    component: Main,
    redirect: "/home",
    children: [
      {
        path: "/home",
        name: "home",
        component: () => import("@/views/Home.vue"),
      },
      {
        path: "/article",
        name: "article",
        component: () => import("@/views/content/Article.vue"),
      },
      {
        path: "/notice",
        name: "notice",
        component: () => import("@/views/Notice.vue"),
      },
      {
        path: "/company",
        name: "company",
        component: () => import("@/views/liubo/Company.vue"),
      },
      {
        path: "/free",
        name: "free",
        component: () => import("@/views/content/Free.vue"),
      },
      {
        path: "/fm",
        name: "fm",
        component: () => import("@/views/knowledge/Fm.vue"),
      },
      {
        path: "/reply",
        name: "reply",
        component: () => import("@/views/reply/Reply.vue"),
      },
      {
        path: "/coursereply",
        name: "coursereply",
        component: () => import("@/views/reply/Coursereply.vue"),
      },
      {
        path: "/articletype",
        name: "articletype",
        component: () => import("@/views/content/Articletype.vue"),
      },
      ...gzhRouter,
      ...rout,
      ...lmh,
      ...lbrouter,
      ...slf,
    ],
  },
]

const router = new VueRouter({
  routes,
})

router.beforeEach((to,from, next) => {
  if(to.path == '/login'){
    return next()
  }
  let userInfo = localStorage.getItem("userInfo")
  if(userInfo){
    next()
  }else{
    Message.error('请先登录😚')
    return next('/login')
  }
})

export default router
